
cc.Class({
    extends: cc.Component,

    properties: {

    },

    onLoad () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.touch_start,this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touch_move,this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.touch_end,this);
        cc.director.getCollisionManager().enabled = true;
        this.pos = this.node.getPosition();
        this.nodeArr = [];
    },
    onCollisionEnter:function(other,self){//碰撞开始
        if(other.tag != 0){
            return;
        }
        this.nodeArr.push(other);
    },
    onCollisionExit:function(other,self){//碰撞结束
        if(other.tag != 0){
            return;
        }
        let index = this.nodeArr.indexOf(other);
        this.nodeArr.splice(index,1);
    },
    touch_start(event){
        // console.log(event);
    },
    touch_move(event){
        this.node.setPosition(event.getLocation().x-280,event.getLocation().y-500)
    },
    touch_end(event){
        if(this.nodeArr.length == this.node.children.length){
            for(let i = 0 ; i < this.nodeArr.length ; i ++){
                let nodeJs = this.nodeArr[i].node.getComponent("block");
                nodeJs.tt = this.node.children[i].getComponent(cc.Sprite).spriteFrame;
            }
            this.node.destroy();
        }else{
            this.node.setPosition(this.pos);
        }
        map.check();
    },


    // update (dt) {},
});
